package fragment;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.qianfeng.lingshijia.PersonCollectActivity;
import com.qianfeng.lingshijia.PersonCouponActivity;
import com.qianfeng.lingshijia.PersonLoginActivity;
import com.qianfeng.lingshijia.PersonMessageActivity;
import com.qianfeng.lingshijia.PersonOrderActivity;
import com.qianfeng.lingshijia.PersonPrizeActivity;
import com.qianfeng.lingshijia.PersonSetActivity;
import com.qianfeng.lingshijia.R;
import com.qianfeng.lingshijia.WebViewActivity;

/**
 * A simple {@link Fragment} subclass.
 */
public class PersonFragment extends BaseFragment implements View.OnClickListener{


    public PersonFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_person, container, false);


    }

    @Override
    public void init(View view) {
         Button  login= (Button)view.findViewById(R.id.id_login);
        Button  regit= (Button) view.findViewById(R.id.id_re);
        ImageView  headImage= (ImageView)view.findViewById(R.id.id_head_image);

        login.setOnClickListener(this);
        regit.setOnClickListener(this);
        headImage.setOnClickListener(this);



        //我的订单
        FrameLayout order= (FrameLayout) view.findViewById(R.id.id_my_order);
        order.setOnClickListener(this);
       // 收藏
      FrameLayout collect= (FrameLayout) view.findViewById(R.id.id_my_collect);
        collect.setOnClickListener(this);
        //优惠卷
        FrameLayout coupon= (FrameLayout) view.findViewById(R.id.id_my_coupon);
        coupon.setOnClickListener(this);
        //我的奖品
        FrameLayout prize= (FrameLayout) view.findViewById(R.id.id_my_prize);
        prize.setOnClickListener(this);
        //申请成为校园店长
        FrameLayout applyscholl= (FrameLayout) view.findViewById(R.id.id_my_apply_school);
        applyscholl.setOnClickListener(this);
        //我是校园店长
        FrameLayout schoolproxy= (FrameLayout) view.findViewById(R.id.id_my_school_proxy);
        schoolproxy.setOnClickListener(this);
        //设置
        FrameLayout setting= (FrameLayout) view.findViewById(R.id.id_my_set);
        setting.setOnClickListener(this);
        //联系客服
        FrameLayout kefu= (FrameLayout) view.findViewById(R.id.id_my_lianxi_kefu);
        kefu.setOnClickListener(this);
        //帮助与反馈
        FrameLayout feedback= (FrameLayout) view.findViewById(R.id.id_my_help_feedback);
        feedback.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.id_head_image:
                startActivity(new Intent(getActivity(),PersonMessageActivity.class));
                break;
            case R.id.id_login:
                startActivity(new Intent(getActivity(),PersonLoginActivity.class));
                break;
            case R.id.id_re:
                break;
            //我的订单
            case R.id.id_my_order:
             startActivity(new Intent(getActivity(), PersonOrderActivity.class));
                break;
            // 收藏
            case R.id.id_my_collect:
                startActivity(new Intent(getActivity(), PersonCollectActivity.class));
                break;
            //优惠卷
            case R.id.id_my_coupon:
                startActivity(new Intent(getActivity(), PersonCouponActivity.class));
                break;
            //我的奖品
            case R.id.id_my_prize:
                startActivity(new Intent(getActivity(), PersonPrizeActivity.class));
                break;
            //申请成为校园店长
            case R.id.id_my_apply_school:
                Intent intent = new Intent(getActivity(), WebViewActivity.class);
                intent.putExtra("url","http://m.haolingzui.com/activity/apply_guide.html?apk=app&token=1a7a21c511bf4a9698a49ce29613cb9a");
                startActivity(intent);
                break;
            //我是校园店长
            case R.id.id_my_school_proxy:
                Intent intent2 = new Intent(getActivity(), WebViewActivity.class);
                intent2.putExtra("url","http://m.haolingzui.com/activity/apply_guide.html?apk=app&token=1a7a21c511bf4a9698a49ce29613cb9a");
                startActivity(intent2);
                break;
            //设置
            case R.id.id_my_set:
                startActivity(new Intent(getActivity(), PersonSetActivity.class));
                break;
            //联系客服
            case R.id.id_my_lianxi_kefu:
                AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());

                View view=LayoutInflater.from(getActivity()).inflate(R.layout.person_lianxikefu,null);
                builder.setView(view);
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();

                break;
            //帮助与反馈
            case R.id.id_my_help_feedback:
                startActivity(new Intent(getActivity(), PersonFeedBackActivity.class));
                break;
        }
    }
}
